package org.framework.customutil;

/**
 * @Title: StrCoverUtil.java .<br>
 * @Package org.framework.customutil .<br>
 * @Description: 补位工具类 .<br>
 * @author 郑成功 .<br>
 * @email a876459952@qq.com .<br>
 * @date 2018-8-10 下午11:35:02.<br>
 * @version V1.0.<br>
 */
public class StrCoverUtil {

	/**
	 * @Description: 获取补位之后的值 .<br>
	 * @param str 待补位字符串.<br>
	 * @param isFront 是否前面补位.<br>
	 * @param coverStr 补位值.<br>
	 * @param length 补位长度.<br>
	 * @return 返回补位值.<br>   
	 * @author 郑成功 .<br>
	 * @date 2018-8-10 下午11:35:17.<br>
	 */
	public static String cover(String str,boolean isFront,String coverStr,int length){
		if(isFront){
			return frontCover(str, coverStr, length);
		}else{
			return behindCover(str, coverStr, length);
		}
	}
	
	/**
	 * @Description: 获取前补位之后的值 .<br>
	 * @param str 待补位字符串.<br>
	 * @param isFront 是否前面补位.<br>
	 * @param coverStr 补位值.<br>
	 * @param length 补位长度.<br>
	 * @return 返回补位值.<br>   
	 * @author 郑成功 .<br>
	 * @date 2018-8-10 下午11:37:05.<br>
	 */
	public static String frontCover(String str,String coverStr,int length){
		int initLength = str.length();
		StringBuffer sb = new StringBuffer();
		while(initLength<length){
			sb.append(coverStr);
			initLength++;
		}
		sb.append(str);
		return sb.toString();
	}
	
	/**
	 * @Description: 获取后补位之后的值 .<br>
	 * @param str 待补位字符串.<br>
	 * @param isFront 是否前面补位.<br>
	 * @param coverStr 补位值.<br>
	 * @param length 补位长度.<br>
	 * @return 返回补位值.<br>   
	 * @author 郑成功 .<br>
	 * @date 2018-8-10 下午11:37:05.<br>
	 */
	public static String behindCover(String str,String coverStr,int length){
		int initLength = str.length();
		StringBuffer sb = new StringBuffer(str);
		while(initLength<length){
			sb.append(coverStr);
			initLength++;
		}
		return sb.toString();
	}
	
}
